<?php

function reequipment_adminapi_createrel($args)
{
    extract($args);

    // Argument check - make sure that all required arguments are present,
    // if not then set an appropriate error message and return
    $invalid = array();
    if (!isset($user_id) || !is_int($user_id)) {
        $invalid[] = 'user_id';
    } 
    if (!isset($company_id) || !is_int($company_id)) {
        $invalid[] = 'company_id';
    } 
   	if (!isset($company_name) || !is_string($company_name)) {
        $invalid[] = 'company_name';
    } 
    if (count($invalid) > 0) {
        $msg = xarML('Invalid #(1)', join(', ', $invalid));
        xarErrorSet(XAR_SYSTEM_EXCEPTION, 'BAD_PARAM', new SystemException($msg));
        return;
    } 
    
    // Get datbase setup
    $dbconn =& xarDBGetConn();
    $xartable =& xarDBGetTables();
    $table = $xartable['rel_eq'];
    // Get next ID in table
    // $nextId = $dbconn->GenId($table);

    // Add item
    $query = "INSERT INTO $table ("
        . " company_id, user_id, company_name )"
        . " VALUES (?, ?, ?)";
    $result =& $dbconn->Execute($query, array($company_id, $user_id, $company_name));
    if (!$result) return;
    // Return the id of the newly created link to the calling process
    return true;
}
?>